package checkers3d.presentation;

import java.awt.*;

/**
 * A visible GUI component that exists as a colored string.
 *
 * @author      Ruben Acuna
 */
public class GUILabel implements IDrawable
{
    /**
    * The position of this component within a GUIContainer or window space.
    */
    private Point position;

    /**
    * The RenderResourceText that defines how this component looks.
    */
    private RenderResourceText resource;

    /**
    * Class constructor that uses a raw text and a AWT color to define the
    * label's appearence and positions it at the coordinates passed.
    *
    * @param text       String that the label displays.
    * @param color      Color of the label.
    * @param position   The position of this object relative to its container.
    * @see RenderResourceText
    */
    public GUILabel(String text, Color color, Point position)
    {
        setDrawPosition(position);
        setRenderResource(new RenderResourceText(text, color));
    }

    /**
    * Class constructor that uses a preexisting RenderResourceText for text data
    * and positions it at the coordinates passed.
    *
    * @param resource   A RenderResourceText that will be used for text.
    * @param position   The position of this object relative to its container.
    * @see RenderResourceText
    */
    public GUILabel(RenderResourceText resource, Point position)
    {
        setDrawPosition(position);
        setRenderResource(resource);
    }

    /**
    * Returns the position of the GUILabel.
    *
    * @return The position of this GUILabel.
    * @see IDrawable
    */
    public Point getDrawPosition()
    {
        return position;
    }

    /**
    * Sets the current the position of the GUILabel.
    *
    * @param  position The new position of this GUILabel.
    * @see IDrawable
    */
    public void setDrawPosition(Point position)
    {
        this.position = position;
    }

    /**
    * Returns the IRenderResource of the GUILabel.
    *
    * @return The IRenderResource of this GUILabel.
    * @see IDrawable
    */
    public IRenderResource getRenderResource()
    {
        return (IRenderResource)resource;
    }

    /**
    * Sets the current the IRenderResource of the GUILabel. The RR must be a
     * RenderResourceText, otherwise it will not be set.
    *
    * @param  resource The new IRenderResource of this GUILabel.
    */
    public void setRenderResource(IRenderResource resource)
    {
        if(resource instanceof RenderResourceText)
            this.resource = (RenderResourceText)resource;
    }

    /**
     * Sets the current text of the label. Wrapper for RenderResourceText.
     *
     * @param text Label text.
     */
    public void setText(String text)
    {
        resource.setText(text);
    }

    /**
     * Returns the current text of the label. Wrapper for RenderResourceText.
     *
     * @return Label text.
     */
    public String getText()
    {
        return resource.getText();
    }

    /**
     * Sets the current color of the label. Wrapper for RenderResourceText.
     *
     * @param color The color of the label.
     */
    public void setColor(Color color)
    {
        resource.setColor(color);
    }

    /**
     * Returns the current color of the label. Wrapper for RenderResourceText.
     *
     * @return The color of the label.
     */
    public Color getColor()
    {
        return resource.getColor();
    }

    /**
     * Returns the height of this GUILabel in pixels. Wrapper for RenderResourceText.
     *
     * @return Height in pixels.
     */
    public int getHeight()
    {
        return resource.getHeight();
    }

    /**
     * Returns the width of this GUILabel in pixels. Wrapper for RenderResourceText.
     *
     * @return Width in pixels.
     */
    public int getWidth()
    {
        return resource.getWidth();
    }

    /**
    * Returns a string representation of the GUILabel which contains
    * information about its position and IRenderResource.
    *
    * @return       A string representation of this GUILabel.
    */
    @Override
    public String toString()
    {
        return getClass().getName() + " -> "
                                    + position.toString()
                                    + ", " + resource.toString();
    }
}